package com.sebiotec.ambassador.viewmodel;

import android.app.Application;

import androidx.annotation.NonNull;
import androidx.lifecycle.AndroidViewModel;

import com.allen.library.interceptor.Transformer;
import com.allen.library.observer.CommonObserver;
import com.sebiotec.ambassador.model.response.DashboardResponse;
import com.sebiotec.ambassador.net.BookApiHelper;
import com.sebiotec.basecommon.utils.constant.SjmConstant;
import com.sebiotec.basecommon.utils.language.LocalManageUtil;
import com.sebiotec.basecommon.utils.tools.ActivityTool;
import com.sebiotec.basecommon.utils.tools.GsonUtil;
import com.sebiotec.basecommon.utils.tools.SPUtils;

import java.util.HashMap;


public class BookViewModel extends AndroidViewModel {
    public BookViewModel(@NonNull Application application) {
        super(application);
    }


    public MyBookDataCallBack mDataCallBack;

    //数据回调接口
    public interface MyBookDataCallBack<T> {
        void onDataSuccessCallBack(T t);
        void onDataFailCallBack(T t);
    }

   public void  getData(final MyBookDataCallBack<DashboardResponse> mDataCallBack){
       HashMap<String,Object> map=new HashMap<String, Object>();
       map.put("LoginId", SPUtils.get(SjmConstant.LOGINID,""));
       map.put("Token", SPUtils.get(SjmConstant.TOKEN,""));
       map.put("Lang", LocalManageUtil.getSMJSetLanguageLocales(ActivityTool.getInstance().getLastActivity()));
       BookApiHelper.geRadomApi()
               .getDashboard(map)
               .compose(Transformer.<String>switchSchedulers())
               .subscribe(new CommonObserver<String>() {
                   @Override
                   protected void onError(String errorMsg) {

                   }

                   @Override
                   protected void onSuccess(String s) {
                       DashboardResponse dashboardResponse = GsonUtil.getGson().fromJson(s, DashboardResponse.class);
                       mDataCallBack.onDataSuccessCallBack(dashboardResponse);
                   }
               });
   }





}
